﻿using UnityEngine;
using System.Collections;

public class LevelSequence : MonoBehaviour {

	public GameObject[] levels;
	public int level = 0;
	public bool dinit = false;

	// Use this for initialization
	void Start () {
		dinit = true;
	}
			
	// Update is called once per frame
	void Update () {
		if (dinit) {dinit = false; startLevel (level);}
		if (levels[level].activeSelf) return;
		nextLevel ();
	}
		            	
	public void nextLevel() {
		startLevelRelative (1);
	}

	public void startLevelRelative(int l) {
		level = (level + l + levels.Length) % levels.Length;
		startLevel (level);
	}

	public void startLevel(int l) {
		level = l;
		for (int i = 0; i < levels.Length; i++) {
			bool b = (level == i);
			if (levels[i].activeSelf != b) {
				levels [i].SetActive (b);
				if (b) {
					TappaGame g = levels[i].GetComponentInChildren<TappaGame>();
					Tappa.game = g;
					//g.stateSet(TappaGame.TappaGameState.Readying);
				}
			}
		}
	}

}
